package com.android.superobstacleavoider;

import javax.microedition.khronos.opengles.GL10;

import android.util.Log;

public class Level {
	private int m_score;
	private float m_scoreTimer = 0;
	private Player m_player;
	private ObstacleCollection m_obstacles;
	private BallCollection m_balls;

	public void setPlayerModel(ModelData model) {
		m_player.setModel(model);
	}

	public void setBoxModel(ModelData model) {
		m_obstacles.setModel(model);
	}
	
	public void setBallModel(ModelData model) {
		m_balls.setModel(model);
	}

	public int getScore() {
		return m_score;
	}

	public Player getPlayer() {
		return m_player;
	}

	// temp
	// //////////////////////////////////////
	private float m_xAngle;
	private float m_yAngle;

	public float getXAngle() {
		return m_xAngle;
	}

	public void setXAngle(float a_xAngle) {
		m_xAngle = a_xAngle;
	}

	public float getYAngle() {
		return m_yAngle;
	}

	public void setYAngle(float a_yAngle) {
		m_yAngle = a_yAngle;
	}

	// ///////////////////////////////////////

	public Level() {
		initialize();
	}

	public void draw(GL10 gl) {
		// draw player & obstacles
		if (m_player.isAlive()) {
			m_player.draw(gl);
			m_obstacles.draw(gl);					
			m_balls.draw(gl);
		}
	}

	public void initialize() {
		m_score = 0;
		m_obstacles = new ObstacleCollection();
		m_balls = new BallCollection();
		// skapar en instans av spelarobjektet
		m_player = new Player();
	}

	private void resetPlayer() {
		m_player.initialize();
	}

	public void update(float a_dt) {
		
		if (m_scoreTimer >= 0.05f) {
			m_score += 1;
			m_scoreTimer = 0.0f;
		} else {
			m_scoreTimer += a_dt;
		}
		
		// player
		if (m_player.isAlive()) {
			// temp
			m_player.setRotZ(0.1f);
			
			float temp = -m_yAngle / 15;				
			m_player.setRotAngle(temp);
						
			
			temp = -m_yAngle / 15;		
			m_player.setPosX(temp);

			//
			
			m_player.update(a_dt);
			
			// Obstacles
			m_obstacles.update(a_dt, m_player);
			
			//balls :D
			m_balls.update(a_dt, m_player, m_score);
			m_score = m_balls.getNewScore();
		}


	}

	public boolean playerIsAlive() {
		return m_player.isAlive();
	}
}
